<?php
/*
	This file is part of PGallery; a FrogCMS plugin.

	PGallery is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	PGallery is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with PGallery.  If not, see <http://www.gnu.org/licenses/>.
*/


class Category extends Record
{
    
	
	const TABLE_NAME = 'pgallery_categories';
    
	
    public $id;
	public $parent_id;
	public $visible;
	public $name;
	public $slug;
    public $description;
	
	
	function __construct($data = FALSE)
	{
        if(is_array($data)){
            $this->setFromData($data);
        }
	}
	
	
	
	
	/**
	 * Return if this category has any child categories
	 */
    public static function hasChildren($id){
        return (boolean) self::countFrom('Category', 'parent_id = '.(int)$id);
    }
	
	
	
	
	/**
	 * Get categories that are children of parent $id
	 */
    public static function childrenOf($id){
        return self::find(array(
			'where' => 'parent_id='.$id,
			'order' => 'name ASC',
		));
    }
	
    
}

/* End of file: pgallery/models/CategoryModel.php */